////////////////////////////////////////////////////////////
// Don't forget to create "log.txt" file in current folder./
////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <string> 
#include <vector>

#include "serialization"

using namespace std;

class Book { 
  SERIALIZABLE
  (
    name,      "Name",
    pageCount, "PageCount",
    weight,    "Weight"
  )

public: 
  Book(){}
  Book(const int _pageCount, 
       const string &_name, 
       const float _weight): 
      pageCount(_pageCount), 
      name(_name), 
      weight(_weight) { }

private: 
  int pageCount;
  string name;
  float weight;
};


class Store {
  SERIALIZABLE 
  (
    price, "BookPrice",
    books, "BookList"
  )

public:
  Store(const double &_price) : 
      price(_price) { }

  void Add(const Book &book) {
    books.push_back(book);
  }

private:
  vector<Book> books;
  double price;
};

////////////////////////////////////

int main() {  
  using namespace Serialization;
  // Fill structures
  Store store(0.01);  
  store.Add(Book(180, "Merciless", 15.4f));
  store.Add(Book(400, "Savor the Danger", 25.5f));
  store.Add(Book(100, "Ghost Story", 8.6f));
  // Serialize to file
  ofstream &writer = ofstream("log.txt");  
  ISerializer<Store> &store_ser = XMLSerializer<Store>(writer);
  store_ser << store;
  writer.close();
  // Deserialize from file
  ifstream &reader = ifstream("log.txt");  
  XMLDeserializer<Store> &store_deser = XMLDeserializer<Store>(reader);
  Store test_store(-1);
  store_deser >> test_store;
  reader.close();
  // Test for equality, write to cout
  ISerializer<Store> &serialize_to_cout = XMLSerializer<Store>(cout);
  serialize_to_cout << test_store;

  cin.ignore();
  return 0;
}